<template>
    <h2> 管理员添加理财</h2>
    <table class="table table-bordered">
        <tr>
            <td>理财产品名称</td>
            <td><input type="text" v-model="state.F_Name" /></td>
        </tr>
        <tr>
            <td>年收益</td>
            <td><input type="text" v-model="state.F_Year" /></td>
        </tr>
        <tr>
            <td>最低金额</td>
            <td><input type="text" v-model="state.F_Money" /></td>
        </tr>
        <tr>
            <td>利息</td>
            <td>
                <select v-model="state.FT_Id">
                    <option value="0">--请选择--</option>
                    <option v-for="item in list" :value="item.FT_Id" >{{item.FT_Year}}年{{(item.FT_Number*100).toFixed(2)}}%</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>风险等级</td>
            <td><input type="radio" v-model="state.F_level" value="0" name="level" />低风险
                <input type="radio" v-model="state.F_level" value="1" name="level" />中风险
                <input type="radio" v-model="state.F_level" value="2" name="level" />高风险
            </td>
        </tr>
        <tr>
            <td></td>
            <td><input class="btn btn-primary" type="button" @click="add" value="添加"/></td>
        </tr>
    </table>
    </template>
    
<script setup lang="ts">
import {reactive,ref,toRefs,onMounted} from 'vue'
import { useRouter,useRoute } from 'vue-router';
import axios from 'axios';
const router=useRouter();
const route=useRoute();
let data:any=reactive({
    state:{
        F_Name:'',
        F_Year:'',
        F_Money:'',
        F_level:'',
        FT_Id:'0',
    },
    list:[],
})
let{state,list} =toRefs(data);
onMounted(()=>{
    bang();
})
const bang=()=>{
    axios({
        url:"/api/Finance/GetInterest",
        method:"get",
    })
    .then(res=>{
        console.log(res);
        list.value=res.data.data;  
    })
    .catch(err=>{
        console.log(err);
        
    })
}
const add=()=>{
    axios({
        url:"/api/Finance/PostFinanceAdd",
        method:"post",
        data:state.value
    })
    .then(res=>{
        console.log(res);
        if(res.data.data>0)
        {
            alert("添加成功");
            router.push("/main/adminFinanceList");
        }
        else{
            alert("添加失败");
            return;
        }
    })
    .catch(err=>{
        console.log(err);
        
    })
}
</script>
    
    
    
<style scoped>
    
</style>
    